package com.sri.ai.lpitools.gwtgui.client.util;

import com.google.gwt.event.logical.shared.BeforeSelectionEvent;
import com.google.gwt.event.logical.shared.BeforeSelectionHandler;
import com.sri.ai.lpitools.gwtgui.client.components.MainView;


/**
 * This listener re-renders the trees of its QRP if their tabs are selected.
 * @author Dylan
 *
 */
public class QueryResultTabListener implements BeforeSelectionHandler<Integer>{

	//The numbers of the tabs, these need to be updated if the structure of QRP is changed.
	private static final int JUSTIFICATION_TAB_NUMBER = 1;
	private static final int TRACE_TAB_NUMBER = 2;
	
	private MainView qp;
	
	/**
	 * Constructor
	 * @param qp the QueryPanel to update.
	 */
	public QueryResultTabListener(MainView qp) {
		this.qp = qp;
	}

	public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
		int tabNum = event.getItem();
		if(tabNum == JUSTIFICATION_TAB_NUMBER || tabNum == TRACE_TAB_NUMBER) {
			qp.renderTrees();
		}
	}
	
	

}
